<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SiteController
 *
 * @author ZangGuoPing
 */
class SiteController extends Controller {
	public $message;
	public function actionIndex() {
		$site = new Site ();
		$modify = $site->find ();
		if (! $modify) {
			$model = $site;
		} else {
			$model = $modify;
		}
		$model->setScenario ( 'default' );
		$this->performAjaxValidation ( $model );
		if (Yii::app ()->request->isPostRequest) {
			$model->attributes = Yii::app ()->request->getPost ( 'Site' );
			if ($model->save ()) {
				$this->message = Yii::t ( 'default', '保存成功' );
			}
		}
		$this->render ( 'index', array ('model' => $model ) );
	}
	public function actionVideo() {
		$site = new Site ();
		$modify = $site->find ();
		if (! $modify) {
			$model = $site;
		} else {
			$model = $modify;
		}
		$model->setScenario ( 'video' );
		$this->performAjaxValidation ( $model );
		if (Yii::app ()->request->isPostRequest) {
			$model->attributes = Yii::app ()->request->getPost ( 'Site' );
			if ($model->save ()) {
				$this->message = Yii::t ( 'default', '保存成功' );
			}
		}
		$this->render ( 'video', array ('model' => $model ) );
	}
	public function actionUser() {
		$site = new Site ();
		$modify = $site->find ();
		if (! $modify) {
			$model = $site;
		} else {
			$model = $modify;
		}
		$model->setScenario ( 'user' );
		$this->performAjaxValidation ( $model );
		if (Yii::app ()->request->isPostRequest) {
			$model->attributes = Yii::app ()->request->getPost ( 'Site' );
			if ($model->save ()) {
				$this->message = Yii::t ( 'default', '保存成功' );
			}
		}
		$this->render ( 'user', array ('model' => $model ) );
	}
	public function actionOther() {
		$site = new Site ();
		$modify = $site->find ();
		if (! $modify) {
			$model = $site;
		} else {
			$model = $modify;
		}
		$model->setScenario ( 'other' );
		$this->performAjaxValidation ( $model );
		if (Yii::app ()->request->isPostRequest) {
			$model->attributes = Yii::app ()->request->getPost ( 'Site' );
			if ($model->save ()) {
				$this->message = Yii::t ( 'default', '保存成功' );
			}
		}
		$this->render ( 'other', array ('model' => $model ) );
	}
	protected function performAjaxValidation($model) {
		if (isset ( $_POST ['ajax'] )) {
			echo CActiveForm::validate ( $model );
			Yii::app ()->end ();
		}
	}

}

?>
